﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using UDS.Components;


namespace UDS.SubModule.SM
{
    /// <summary>
    /// MsgSend 的摘要说明。
    /// </summary>
    public class MsgSend : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Button btnSend;
        protected System.Web.UI.WebControls.TextBox txtContent;
        protected System.Web.UI.WebControls.Label lblContent;
        public string SendTo = "", MobileSendTo = "", SendToRealName = "", MobileSendToRN = "", AdditionalNo = "", Type = "";
        protected System.Web.UI.WebControls.Label lblLReceiver;
        protected System.Web.UI.WebControls.Label lblAdditionalNo;
        protected System.Web.UI.WebControls.Label lblRemind;
        protected System.Web.UI.WebControls.Button btnReturn;
        protected System.Web.UI.WebControls.Label lblShortCut;
        protected System.Web.UI.WebControls.Label lblMReceiver;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Type = (Request.QueryString["Type"] != null) ? Request.QueryString["Type"].ToString() : "1";
                if (Type == "1")
                {
                    SendTo = (Request.QueryString["SendTo"] != null) ? Request.QueryString["SendTo"].ToString() + "," : "";
                    SendToRealName = (Request.QueryString["SendToRealName"] != null) ? Request.QueryString["SendToRealName"].ToString() + "," : "";
                }
                if (Type == "2")
                {
                    MobileSendTo = (Request.QueryString["SendTo"] != null) ? Request.QueryString["SendTo"].ToString() + "," : "";
                    MobileSendToRN = (Request.QueryString["SendToRealName"] != null) ? Request.QueryString["SendToRealName"].ToString() + "," : "";
                }
                if (Type == "3")
                {
                    AdditionalNo = (Request.QueryString["SendTo"] != null) ? Request.QueryString["SendTo"].ToString() + "," : "";
                }
                InitData();
            }
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN：该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
            this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void InitData()
        {


        }

        private void btnSend_Click(object sender, System.EventArgs e)
        {
            string ErrorMsg = "";
            string Username = SiteContext.Current.UserName.ToString();
            this.SendTo = Request.Form["hdnTxtSendTo"].ToString();
            this.MobileSendTo = Request.Form["hdnTxtMobileSendTo"].ToString();
            this.SendToRealName = Request.Form["txtSendTo"].ToString();
            this.MobileSendToRN = Request.Form["txtMobileSendTo"].ToString();
            this.AdditionalNo = Request.Form["txtAdditionalNo"].ToString();
            if (SendTo != "") //发送短信至站内用户
            {
                bool flag = SMS.SendMsg(Username, SendTo, this.txtContent.Text, SMSType.SiteMessage, DateTime.Now, "", 0, 0);
                if (flag)
                {
                    Response.Write("<script language=javascript>alert('站内短信发送成功');</script>");
                    //Response.Redirect("MsgSend.aspx");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('站内短信发送失败');</script>");
                    //Response.Redirect("MsgSend.aspx");
                }
            }


            if (MobileSendTo != "")//发送至站内手机用户
            {
                bool flag = SMS.SendMsg(Username, MobileSendTo, this.txtContent.Text, SMSType.LocalSMS, DateTime.Now, AdditionalNo, 0, 0);
                if (flag)
                {
                    Response.Write("<script language=javascript>alert('站内手机短讯已经成功存储至消息阵列');</script>");
                    //Response.Redirect("MsgSend.aspx");
                }
                else
                {
                    //ErrorMsg = GetErrorMsg(Code);
                    Response.Write("<script language=javascript>alert('手机短讯存储失败,请重试');</script>");
                    //Response.Redirect("MsgSend.aspx");
                }
            }


            if (AdditionalNo != "")//发送至站外手机用户
            {
                // An exception will be thrown when failing to send SMS.
                bool flag = SMS.SendMsg(Username, MobileSendTo, this.txtContent.Text, SMSType.OutSMS, DateTime.Now, AdditionalNo, 0, 0);
                if (flag)
                {
                    Response.Write("<script language=javascript>alert('站外手机短讯已经成功存储至消息阵列');</script>");
                    //Response.Redirect("MsgSend.aspx");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('手机短讯存储失败,请重试');</script>");
                    //Response.Redirect("MsgSend.aspx");
                }
            }

        }

        private void btnReturn_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("Index.aspx");
        }


    }
}
